import React, { PureComponent } from 'react';
import {
    Row,
    Col,
    Card,
    Form,
    Button,
    Input,
    DatePicker,
    Table,
    Select,
    Icon,
    Divider,
    Popconfirm,
    Modal,
    message,
    Alert,
    Steps
} from 'antd';
import moment from 'moment';
import { connect } from 'dva';
import router from 'umi/router';
const FormItem = Form.Item;
const Option = Select.Option;

@Form.create()
@connect()
export default class EmergAddEquipOther extends PureComponent {
    constructor(props) {
        super(props);
        this.state = {
            visible: false,
        };
        this.dispatch = this.props.dispatch;
    }
    submitAddValues = (values) => {
                values.zbbid = this.props.zbbid;
                const hide = message.loading('正在新增...', 0);
                this.props.dispatch({
                    type: 'emergency/fetchEmergencyAddEquipOther',
                    payload: {
                        model: values,
                    },
                    callback: response => {
                        hide();
                        if (response.status) {
                            message.success('新增成功');
                            this.setState({ visible: false });
                            this.props.fetchEmergencyQueryEquipOther();
                        } else {
                            message.error('新增失败');
                            console.log(response.ErrorMessage);
                        }
                    },
                });
    }
    submitEditValues=(values)=>{
        const hide = message.loading('正在编辑...', 0);
        this.props.dispatch({
            type: 'emergency/fetchEmergencyEditEquipOther',
            payload: {
                model: values,
            },
            callback: response => {
                hide();
                if (response.status) {
                    message.success('编辑成功');
                    this.setState({ visible: false });
                    this.props.fetchEmergencyQueryEquipOther();
                } else {
                    message.error('编辑失败');
                    console.log(response.ErrorMessage);
                }
            },
        });
        
    }
    submmitFormValues=()=>{
        this.props.form.validateFields((err, values) => {
            if (!err) {
                
                if(values.mxid)this.submitEditValues(values);
                else this.submitAddValues(values);
            }
        })
    }
    setFormValues=({values=null}={})=>{
        
        this.props.form.setFieldsValue(values);

    }
    componentDidMount() {
        // debugger
        this.props.OnRef({ ref: this, type: 'AddForm' });
    }
    render() {
        const { getFieldDecorator } = this.props.form;

        const formItemLayout = {
            labelCol: {
                xs: { span: 24 },
                sm: { span: 12 },
            },
            wrapperCol: {
                xs: { span: 24 },
                sm: { span: 24 },
            },
        };
        const width = '300px';
        return (
            <><Modal
                title="新增"
                width={'60%'}
                style={{ top: 20 }}
                destroyOnClose
                visible={this.state.visible}
                onOk={() => {
                    this.submmitFormValues();
                }}
                onCancel={() => {
                    this.setState({ visible: false });
                }}

            >
                <Card style={{ margin: '5px 0' }}>
                    <Form labelAlign="left" layout={'inline'} {...formItemLayout}>
                        <Row>
                            <Col span={8} offset={4}>
                                <FormItem label="名称" >
                                    {getFieldDecorator('mc', {
                                        initialValue: null,
                                    })(<Input placeholder="名称" style={{ width: width }} />)}
                                </FormItem>
                            </Col>
                            <Col span={12}>
                                <FormItem label="类型" >
                                    {getFieldDecorator('lx', {
                                        initialValue: null,
                                    })(<Input placeholder="类型" style={{ width: width }} />)}
                                </FormItem></Col>
                        </Row>
                        <Row>
                            <Col span={8} offset={4}>
                                <FormItem label="数量" >
                                    {getFieldDecorator('sl', {
                                        initialValue: null,
                                    })(<Input placeholder="数量" style={{ width: width }} />)}
                                </FormItem></Col>
                        </Row>
                      
                        <Row style={{display:'none'}}>
                        <Col span={8} offset={4}>
                                <FormItem label="mxid" >
                                    {getFieldDecorator('mxid', {
                                        initialValue: null,
                                    })(<Input placeholder="联系方式" style={{ width: width }} />)}
                                </FormItem>
                            </Col>
                        </Row>
                        <Row style={{display:'none'}}>
                        <Col span={8} offset={4}>
                                <FormItem label="zbbid" >
                                    {getFieldDecorator('zbbid', {
                                        initialValue: null,
                                    })(<Input placeholder="联系方式" style={{ width: width }} />)}
                                </FormItem>
                            </Col>
                        </Row>
                    </Form>
                   {/* <Editor/> */}
                </Card>
            </Modal></>
        )
    }
}